<template>
  <div
    class="modal"
    v-if="show"
  >
    <div
      v-if="type==='alert'"
      class="alertModalContent"
    >
      <div class="alertModal modalContent">
        <div class="content">
          {{content}}
        </div>
        <div
          class="btn"
          @click="okCall"
        >
          {{onOkTxt}}
        </div>
      </div>
    </div>
    <div
      v-if="type === 'toast'"
      class="toastModal modalContent"
    >
      {{content}}
    </div>
    <div
      v-if="type === 'loading'"
      class="loadingModal modalContent"
    >
      <div class="sk-fading-circle">
        <div class="sk-circle1 sk-circle"></div>
        <div class="sk-circle2 sk-circle"></div>
        <div class="sk-circle3 sk-circle"></div>
        <div class="sk-circle4 sk-circle"></div>
        <div class="sk-circle5 sk-circle"></div>
        <div class="sk-circle6 sk-circle"></div>
        <div class="sk-circle7 sk-circle"></div>
        <div class="sk-circle8 sk-circle"></div>
        <div class="sk-circle9 sk-circle"></div>
        <div class="sk-circle10 sk-circle"></div>
        <div class="sk-circle11 sk-circle"></div>
        <div class="sk-circle12 sk-circle"></div>
      </div>
    </div>
    <div
      v-if="type === 'confirm'"
      class="confirmModalContent "
    >
      <div class="confirmModal modalContent">
        <div class="content">
          {{content}}
        </div>
        <div class="btns">
          <div
            class="okBtn"
            @click="okCall"
          >
            {{onOkTxt}}
          </div>
          <div
            class="cancelBtn"
            @click="onCancel"
          >
            {{onCancelTxt}}
          </div>
        </div>
      </div>

    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      show: true,
      type: 'alert',
      content: '',
      onOkTxt: '确定',
      onCancelTxt: '取消'
    }
  },
  mounted() {},
  methods: {
    okCall(e) {
      this.okCallback({ ...arguments })
      this.modalHide()
    },
    modalShow(obj) {
      this.content = obj.content || ''
      this.type = obj.type
      this.show = true
      if (this.type === 'toast') {
        setTimeout(() => {
          this.show = false
        }, 2000)
      }
    },
    onCancel() {
      this.onCancelCallback({ ...arguments })
      this.modalHide()
    },
    modalHide() {
      this.show = false
    }
  }
}
</script>
<style lang="less" scoped>
.modal {
  position: fixed;
  height: 100%;
  width: 100%;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, 0);
  z-index: 999;
}
.modalContent {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.alertModalContent,
.confirmModalContent {
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
}
.alertModal,
.confirmModal {
  width: 500px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 1);
  .title {
    font-size: 28px;
    text-align: center;
    font-weight: bold;
    padding: 10px 0;
  }
  .content {
    font-size: 28px;
    text-align: center;
    padding: 34px 30px;
    border-bottom: 1px solid #ebebeb;
  }
  .btn {
    font-size: 32px;
    text-align: center;
    padding: 20px 0;
  }
  .btns {
    font-size: 32px;
    text-align: center;
    height: 84px;
    display: flex;
    align-items: center;
    .okBtn {
      flex: 1;
      height: 100%;
      line-height: 84px;
      border-right: 1px solid #ebebeb;
    }
    .cancelBtn {
      height: 100%;
      line-height: 84px;
      flex: 1;
    }
  }
}
.toastModal {
  min-width: 350px;
  padding: 30px 10px;
  text-align: center;
  font-size: 32px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  border-radius: 10px;
}
.loadingModal {
  width: 200px;
  padding: 30px 0;
  text-align: center;
  font-size: 32px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  border-radius: 10px;
}
.sk-fading-circle {
  margin: 15px auto;
  width: 80px;
  height: 80px;
  position: relative;
}
.sk-fading-circle .sk-circle {
  width: 100%;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
}
.sk-fading-circle .sk-circle:before {
  content: '';
  display: block;
  margin: 0 auto;
  width: 15%;
  height: 15%;
  background-color: #fff;
  border-radius: 100%;
  -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both;
  animation: sk-circleFadeDelay 1.2s infinite ease-in-out both;
}
.sk-fading-circle .sk-circle2 {
  -webkit-transform: rotate(30deg);
  -ms-transform: rotate(30deg);
  transform: rotate(30deg);
}
.sk-fading-circle .sk-circle3 {
  -webkit-transform: rotate(60deg);
  -ms-transform: rotate(60deg);
  transform: rotate(60deg);
}
.sk-fading-circle .sk-circle4 {
  -webkit-transform: rotate(90deg);
  -ms-transform: rotate(90deg);
  transform: rotate(90deg);
}
.sk-fading-circle .sk-circle5 {
  -webkit-transform: rotate(120deg);
  -ms-transform: rotate(120deg);
  transform: rotate(120deg);
}
.sk-fading-circle .sk-circle6 {
  -webkit-transform: rotate(150deg);
  -ms-transform: rotate(150deg);
  transform: rotate(150deg);
}
.sk-fading-circle .sk-circle7 {
  -webkit-transform: rotate(180deg);
  -ms-transform: rotate(180deg);
  transform: rotate(180deg);
}
.sk-fading-circle .sk-circle8 {
  -webkit-transform: rotate(210deg);
  -ms-transform: rotate(210deg);
  transform: rotate(210deg);
}
.sk-fading-circle .sk-circle9 {
  -webkit-transform: rotate(240deg);
  -ms-transform: rotate(240deg);
  transform: rotate(240deg);
}
.sk-fading-circle .sk-circle10 {
  -webkit-transform: rotate(270deg);
  -ms-transform: rotate(270deg);
  transform: rotate(270deg);
}
.sk-fading-circle .sk-circle11 {
  -webkit-transform: rotate(300deg);
  -ms-transform: rotate(300deg);
  transform: rotate(300deg);
}
.sk-fading-circle .sk-circle12 {
  -webkit-transform: rotate(330deg);
  -ms-transform: rotate(330deg);
  transform: rotate(330deg);
}
.sk-fading-circle .sk-circle2:before {
  -webkit-animation-delay: -1.1s;
  animation-delay: -1.1s;
}
.sk-fading-circle .sk-circle3:before {
  -webkit-animation-delay: -1s;
  animation-delay: -1s;
}
.sk-fading-circle .sk-circle4:before {
  -webkit-animation-delay: -0.9s;
  animation-delay: -0.9s;
}
.sk-fading-circle .sk-circle5:before {
  -webkit-animation-delay: -0.8s;
  animation-delay: -0.8s;
}
.sk-fading-circle .sk-circle6:before {
  -webkit-animation-delay: -0.7s;
  animation-delay: -0.7s;
}
.sk-fading-circle .sk-circle7:before {
  -webkit-animation-delay: -0.6s;
  animation-delay: -0.6s;
}
.sk-fading-circle .sk-circle8:before {
  -webkit-animation-delay: -0.5s;
  animation-delay: -0.5s;
}
.sk-fading-circle .sk-circle9:before {
  -webkit-animation-delay: -0.4s;
  animation-delay: -0.4s;
}
.sk-fading-circle .sk-circle10:before {
  -webkit-animation-delay: -0.3s;
  animation-delay: -0.3s;
}
.sk-fading-circle .sk-circle11:before {
  -webkit-animation-delay: -0.2s;
  animation-delay: -0.2s;
}
.sk-fading-circle .sk-circle12:before {
  -webkit-animation-delay: -0.1s;
  animation-delay: -0.1s;
}

@-webkit-keyframes sk-circleFadeDelay {
  0%,
  39%,
  100% {
    opacity: 0;
  }
  40% {
    opacity: 1;
  }
}

@keyframes sk-circleFadeDelay {
  0%,
  39%,
  100% {
    opacity: 0;
  }
  40% {
    opacity: 1;
  }
}
</style>
